package com.jilian.mydemo.modul.order.adapter;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jilian.mydemo.R;
import com.jilian.mydemo.common.dto.OrderDto;
import com.jilian.mydemo.listener.CustomItemClickListener;
import com.jilian.mydemo.modul.order.ui.HydraulicDeclarationActivity;
import com.jilian.mydemo.modul.order.ui.PaySuccessActivity;
import com.jilian.mydemo.utils.ToastUitl;

import java.util.List;


public class FourOrderAdapter extends RecyclerView.Adapter<FourOrderAdapter.ViewHolder> {
    private Activity mContext;
    private List<OrderDto> datas;
    private CustomItemClickListener listener;



    public FourOrderAdapter(Activity context, List<OrderDto> datas, CustomItemClickListener listener) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_four_order, parent, false);
        ViewHolder viewHolder = new ViewHolder(view, listener);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tvNo.setText("服务单号："+datas.get(position).getOrderNo());
        holder.tvType.setText(datas.get(position).getServiceType());
        holder.tvName.setText(datas.get(position).getCustomerName());
        holder.tvDate.setText(datas.get(position).getBookTime());
        holder.tvAdress.setText(datas.get(position).getServiceAddress());
        holder.tvOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!("1".equals(datas.get(position).getIsLeader()))&&"1".equals(datas.get(position).getIsMore())) {
                    ToastUitl.showImageToastTips("只有队长可以操作");
                    return;
                }
                Intent intent = new Intent(mContext, HydraulicDeclarationActivity.class);
                intent.putExtra("orderId", datas.get(position).getId());
                intent.putExtra("orderDto", datas.get(position));
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private TextView tvNo;
        private TextView tvType;
        private TextView tvName;
        private TextView tvDate;
        private TextView tvAdress;
        private TextView tvOk;







        public ViewHolder(final View itemView, final CustomItemClickListener listener) {
            super(itemView);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    listener.onItemClick(itemView, getAdapterPosition());
                }
            });
            tvOk = (TextView) itemView.findViewById(R.id.tv_ok);
            tvNo = (TextView)itemView. findViewById(R.id.tv_no);
            tvType = (TextView) itemView. findViewById(R.id.tv_type);
            tvName = (TextView) itemView. findViewById(R.id.tv_name);
            tvDate = (TextView) itemView. findViewById(R.id.tv_date);
            tvAdress = (TextView) itemView. findViewById(R.id.tv_adress);


        }

    }
}
